/**
 * Bestpay.com.cn Inc.
 * Copyright (c) 2011-2018 All Rights Reserved.
 */
package com.sgzn.sgpay.persistence.manager;

import com.sgzn.sgpay.persistence.dao.TDeviceMapper;
import com.sgzn.sgpay.persistence.domain.TDevice;
import com.sgzn.sgpay.persistence.domain.TDeviceExample;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author huangsenguang
 * @version Id: DeviceDaoManager.java, v 0.1 2018/5/19 11:04 huangsenguang Exp $$
 */
@Slf4j
@Component
public class DeviceDaoManager {
    @Resource
    private TDeviceMapper tDeviceMapper;

    /**
     * 根据设备id 获取设备信息
     * @param deviceId
     * @return
     */
    public TDevice getTDevice(String deviceId) {
        List<TDevice> tDevices = this.getTDeviceList(deviceId);
        if (CollectionUtils.isEmpty(tDevices)) {
            return null;
        }
        return tDevices.get(0);
    }

    /**
     * 根据设备id 获取设备信息
     * @param deviceId
     * @return
     */
    public List<TDevice> getTDeviceList(String deviceId) {
        TDeviceExample tDeviceExample = new TDeviceExample();
        tDeviceExample.createCriteria().andDeviceIdEqualTo(deviceId);
        return tDeviceMapper.selectByExample(tDeviceExample);
    }

    /**
     * 获取指定多个门店下的所有设备
     * @param shopIdList
     * @return
     */
    public List<TDevice> getAllDevices(List<String> shopIdList){
        TDeviceExample example = new TDeviceExample();
        TDeviceExample.Criteria cra = example.createCriteria();
        cra.andShopIdIn(shopIdList);
        List<TDevice> list = tDeviceMapper.selectByExample(example);
        return list;
    }

    /**
     * 获取指定多个门店下的所有设备数量
     * @param shopIdList
     * @return
     */
    public int countDevices(List<String> shopIdList){
        TDeviceExample example = new TDeviceExample();
        TDeviceExample.Criteria cra = example.createCriteria();
        cra.andShopIdIn(shopIdList);
        return tDeviceMapper.countByExample(example);
    }

    /**
     * 获取指定商户下所有设备
     * @param merchantId
     * @return
     */
    public List<TDevice> getDevicesByMch(String merchantId){
        TDeviceExample example = new TDeviceExample();
        TDeviceExample.Criteria cra = example.createCriteria();
        cra.andMerchantIdEqualTo(merchantId);
        List<TDevice> list = tDeviceMapper.selectByExample(example);
        return list;
    }

    /**
     * 获取设备id集合的所有设备
     * @param deviceIdList
     * @return
     */
    public List<TDevice> getDevicesBydeviceIds(List<String> deviceIdList){
        TDeviceExample example = new TDeviceExample();
        TDeviceExample.Criteria cra = example.createCriteria();
        cra.andDeviceIdIn(deviceIdList);
        List<TDevice> list = tDeviceMapper.selectByExample(example);
        return list;
    }
}

